/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cadastro;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import utilitario.Arquivo;
import utilitario.Cliente;
import javax.swing.table.DefaultTableModel;
import principalcontrole.principal;

/**
 *
 * @author marcos
 */
public class cliente extends javax.swing.JFrame {

    public ArrayList<Cliente> lista_de_clientes = new ArrayList<>();
    principal tela_principal;

    public cliente(principal tela){
        this();
        this.tela_principal = tela;

    }

    public cliente() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        tf_nome_cli = new javax.swing.JTextField();
        tf_end_cli = new javax.swing.JTextField();
        tf_num_cli = new javax.swing.JTextField();
        tf_compl_cli = new javax.swing.JTextField();
        tf_bairro_cli = new javax.swing.JTextField();
        tf_cidade_cli = new javax.swing.JTextField();
        btn_masc = new javax.swing.JRadioButton();
        btn_fem = new javax.swing.JRadioButton();
        com_estcivil_cli = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        tf_email_cli = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        btn_salvar_cli = new javax.swing.JButton();
        btn_novo_cli = new javax.swing.JButton();
        btn_exclude_cli = new javax.swing.JButton();
        btn_edit_cli = new javax.swing.JButton();
        tf_data_nasc_cli = new javax.swing.JFormattedTextField();
        tf_cpf_cli = new javax.swing.JFormattedTextField();
        tf_cep_cli = new javax.swing.JFormattedTextField();
        tf_tel_cli = new javax.swing.JFormattedTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabela_cli = new javax.swing.JTable();
        fundo = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(815, 636));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        getContentPane().setLayout(null);

        jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true));
        jPanel1.setOpaque(false);

        btn_masc.setLabel("Masculino");
        btn_masc.setMaximumSize(new java.awt.Dimension(71, 20));
        btn_masc.setMinimumSize(new java.awt.Dimension(71, 20));
        btn_masc.setOpaque(false);
        btn_masc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_mascActionPerformed(evt);
            }
        });

        btn_fem.setText("Feminino");
        btn_fem.setOpaque(false);
        btn_fem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_femActionPerformed(evt);
            }
        });

        com_estcivil_cli.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Solteiro", "Casado", "Divorciado", "Sep. Jud.", "Viúvo" }));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Cpf:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Nome Completo:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Data Nasc.:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("Sexo:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Estado Civil:");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Telefone:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setText("email: ");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel8.setText("Endereço: ");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel9.setText("nº: ");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel10.setText("Complemento: ");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel11.setText("Cep:");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel12.setText("Bairro: ");

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel13.setText("Cidade:");

        btn_salvar_cli.setIcon(new javax.swing.ImageIcon(getClass().getResource("/save.png"))); // NOI18N
        btn_salvar_cli.setToolTipText("Salvar");
        btn_salvar_cli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_salvar_cliActionPerformed(evt);
            }
        });

        btn_novo_cli.setIcon(new javax.swing.ImageIcon(getClass().getResource("/novo.png"))); // NOI18N
        btn_novo_cli.setToolTipText("novo");
        btn_novo_cli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_novo_cliActionPerformed(evt);
            }
        });

        btn_exclude_cli.setIcon(new javax.swing.ImageIcon(getClass().getResource("/excluir.png"))); // NOI18N
        btn_exclude_cli.setToolTipText("Excluir");
        btn_exclude_cli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_exclude_cliActionPerformed(evt);
            }
        });

        btn_edit_cli.setIcon(new javax.swing.ImageIcon(getClass().getResource("/editar.png"))); // NOI18N
        btn_edit_cli.setToolTipText("Editar");
        btn_edit_cli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_edit_cliActionPerformed(evt);
            }
        });

        try {
            tf_data_nasc_cli.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            tf_cpf_cli.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            tf_cep_cli.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#####-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            tf_tel_cli.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(tf_end_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tf_num_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(tf_bairro_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(28, 28, 28)
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tf_cep_cli)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tf_compl_cli))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tf_cidade_cli))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btn_masc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btn_fem)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(com_estcivil_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_tel_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_email_cli))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel12)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tf_cpf_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tf_nome_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(21, 21, 21)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tf_data_nasc_cli, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)))))
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(235, 235, 235)
                .addComponent(btn_novo_cli)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_salvar_cli)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_edit_cli)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_exclude_cli)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tf_cpf_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tf_nome_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tf_data_nasc_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btn_fem, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(com_estcivil_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btn_masc, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tf_tel_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(tf_email_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(40, 40, 40)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tf_end_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tf_num_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_compl_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(tf_bairro_cli)
                        .addComponent(tf_cidade_cli)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tf_cep_cli, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btn_salvar_cli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_novo_cli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_exclude_cli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_edit_cli, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(123, 123, 123))
        );

        getContentPane().add(jPanel1);
        jPanel1.setBounds(30, 180, 750, 260);

        tabela_cli.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cpf", "Nome", "Email", "Telefone"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tabela_cli.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabela_cliMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tabela_cli);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(30, 450, 750, 130);

        fundo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fundo_fornecedor.png"))); // NOI18N
        getContentPane().add(fundo);
        fundo.setBounds(0, 0, 800, 600);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 750, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 130, Short.MAX_VALUE)
        );

        getContentPane().add(jPanel2);
        jPanel2.setBounds(30, 450, 750, 130);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_mascActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_mascActionPerformed
        // TODO add your handling code here:
        if(btn_masc.isSelected()){

            btn_fem.setSelected(false);

        }

    }//GEN-LAST:event_btn_mascActionPerformed

    private boolean verifica_cpf(String cpf){
        int tamanho = lista_de_clientes.size();
        for(int i=0; i<tamanho; i++){
            if (cpf.equals(lista_de_clientes.get(i).getCpf())){
                return true;
            }
        }
        return false;
    }

    private void btn_salvar_cliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_salvar_cliActionPerformed
        Cliente cli = new Cliente("","","","","","","","","","","","","");


                if (tf_cpf_cli.getText().equals("") || tf_nome_cli.getText().equals("") || tf_data_nasc_cli.getText().equals("")
                || tf_tel_cli.getText().equals("") || tf_end_cli.getText().equals("") || tf_num_cli.getText().equals("")
                || tf_bairro_cli.getText().equals("") || tf_cep_cli.getText().equals("") || tf_cidade_cli.getText().equals("")
                || (btn_masc.isSelected() == false && btn_fem.isSelected() == false)){
            JOptionPane.showMessageDialog(this, "Preencha todos os campos para continuar");
        }
                else if(verifica_cpf(tf_cpf_cli.getText()) == true){
                    JOptionPane.showMessageDialog(this, "Já existe um cliente cadastrado com esse cpf!");
                }
                else{
        cli.setCpf(tf_cpf_cli.getText());
        cli.setNome(tf_nome_cli.getText());
        cli.setNasc(tf_data_nasc_cli.getText());
       if(btn_masc.isSelected()){
           cli.setSexo("Masculino");
       }
       if (btn_fem.isSelected()){
           cli.setSexo("Feminino");
       }

        if (com_estcivil_cli.getSelectedIndex() == 0){
            cli.setEst_civil("Solteiro");
        }
        if (com_estcivil_cli.getSelectedIndex() == 1){
            cli.setEst_civil("Casado");
        }
        if (com_estcivil_cli.getSelectedIndex() == 2){
            cli.setEst_civil("Divorciado");
        }
        if (com_estcivil_cli.getSelectedIndex() == 3){
            cli.setEst_civil("Sep. Jud.");
        }
        if (com_estcivil_cli.getSelectedIndex() == 4){
            cli.setEst_civil("Viuvo");
        }
        cli.setTel(tf_tel_cli.getText());
        cli.setEmail(tf_email_cli.getText());
        cli.setEnd(tf_end_cli.getText());
        cli.setNum(tf_num_cli.getText());
        cli.setComplem(tf_compl_cli.getText());
        cli.setBairro(tf_bairro_cli.getText());
        cli.setCep(tf_cep_cli.getText());
        cli.setCidade(tf_cidade_cli.getText());

        lista_de_clientes.add(cli);
        this.addLinha();
        inserir_na_tabela(lista_de_clientes);
        Arquivo.armazenarCliente(lista_de_clientes);
                }
    }//GEN-LAST:event_btn_salvar_cliActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        lista_de_clientes = Arquivo.lerCliente();

        if (lista_de_clientes.isEmpty() == true) {
            System.out.println("Nenhum Dado");
        }
        if (lista_de_clientes.isEmpty() == false) {
                    for (int i = 0; i < lista_de_clientes.size(); i++) {
            this.addLinha();
                }
            inserir_na_tabela(lista_de_clientes);
        }
    }//GEN-LAST:event_formWindowOpened

    private void btn_edit_cliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_edit_cliActionPerformed
        edit();
        inserir_na_tabela(lista_de_clientes);
        Arquivo.armazenarCliente(lista_de_clientes);

    }//GEN-LAST:event_btn_edit_cliActionPerformed

    private void tabela_cliMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabela_cliMouseClicked
        setform();
    }//GEN-LAST:event_tabela_cliMouseClicked

    private void btn_exclude_cliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_exclude_cliActionPerformed
        int sel = tabela_cli.getSelectedRow();
        if (tabela_cli.getSelectedRow() > -1) {
            switch (JOptionPane.showConfirmDialog(null, "Tem certeza que quer deletar este cliente?\n", "Deletar", JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_OPTION)) {
                case 0: {
                    removeLinha(tabela_cli.getSelectedRow());
                    lista_de_clientes.remove(sel);
                    Arquivo.armazenarCliente(lista_de_clientes);
                    limpa_form();
                }
            }
        }else{
            System.out.println("Selecione um cliente para ser deletado");
        }
    }//GEN-LAST:event_btn_exclude_cliActionPerformed

    private void btn_novo_cliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_novo_cliActionPerformed
        limpa_form();
    }//GEN-LAST:event_btn_novo_cliActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
              tela_principal.setEnabled(true);
        Thread t = new Thread(tela_principal);
        t.start();
    }//GEN-LAST:event_formWindowClosed

    private void btn_femActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_femActionPerformed
        // TODO add your handling code here:
        if(btn_fem.isSelected()){

            btn_masc.setSelected(false);

        }
    }//GEN-LAST:event_btn_femActionPerformed

    private void limpa_form(){
        tf_cpf_cli.setText("");
        tf_nome_cli.setText("");
        tf_email_cli.setText("");
        tf_tel_cli.setText("");
        tf_end_cli.setText("");
        tf_num_cli.setText("");
        tf_compl_cli.setText("");
        tf_bairro_cli.setText("");
        tf_cep_cli.setText("");
        tf_cidade_cli.setText("");
        tf_data_nasc_cli.setText("");
    }

    private void removeLinha(int posicao) {
        DefaultTableModel c = (DefaultTableModel) tabela_cli.getModel();
        c.removeRow(posicao);
    }

    private void addLinha() {
        DefaultTableModel c = (DefaultTableModel) tabela_cli.getModel();
        Object[] linha = {null, null, null, null, null, null};
        c.addRow(linha);
    }

    private void setform(){
    int tamanho = lista_de_clientes.size();
    tf_cpf_cli.setText(tabela_cli.getValueAt(tabela_cli.getSelectedRow(), 0)+"");
    tf_nome_cli.setText(tabela_cli.getValueAt(tabela_cli.getSelectedRow(), 1)+"");
    tf_email_cli.setText(tabela_cli.getValueAt(tabela_cli.getSelectedRow(), 2)+"");
    tf_tel_cli.setText(tabela_cli.getValueAt(tabela_cli.getSelectedRow(), 3)+"");
            for (int i=0; i<tamanho; i++){
            if ((tabela_cli.getValueAt(tabela_cli.getSelectedRow(), 0)+"").equals(lista_de_clientes.get(i).getCpf())){
                tf_end_cli.setText(lista_de_clientes.get(i).getEnd());
                tf_num_cli.setText(lista_de_clientes.get(i).getNum());
                tf_compl_cli.setText(lista_de_clientes.get(i).getComplem());
                tf_bairro_cli.setText(lista_de_clientes.get(i).getBairro());
                tf_cep_cli.setText(lista_de_clientes.get(i).getCep());
                tf_cidade_cli.setText(lista_de_clientes.get(i).getCidade());
                tf_data_nasc_cli.setText(lista_de_clientes.get(i).getNasc());
            }
        }
    }

    private void edit(){
    int tamanho = lista_de_clientes.size();
    int sel = tabela_cli.getSelectedRow();
    lista_de_clientes.get(sel).setCpf(tf_cpf_cli.getText());
    lista_de_clientes.get(sel).setNome(tf_nome_cli.getText());
    lista_de_clientes.get(sel).setNasc(tf_data_nasc_cli.getText());
    lista_de_clientes.get(sel).setEmail(tf_email_cli.getText());
    lista_de_clientes.get(sel).setTel(tf_tel_cli.getText());
    lista_de_clientes.get(sel).setEnd(tf_end_cli.getText());
    lista_de_clientes.get(sel).setNum(tf_num_cli.getText());
    lista_de_clientes.get(sel).setComplem(tf_compl_cli.getText());
    lista_de_clientes.get(sel).setBairro(tf_bairro_cli.getText());
    lista_de_clientes.get(sel).setCep(tf_cep_cli.getText());
    lista_de_clientes.get(sel).setCidade(tf_cidade_cli.getText());
    }

    private void inserir_na_tabela(ArrayList<Cliente> lista){
        int tamanho = lista.size();

        for(int i=0; i <tamanho; i++){
            tabela_cli.getModel().setValueAt(lista.get(i).getCpf(), i, 0);
            tabela_cli.getModel().setValueAt(lista.get(i).getNome(), i, 1);
            tabela_cli.getModel().setValueAt(lista.get(i).getEmail(), i, 2);
            tabela_cli.getModel().setValueAt(lista.get(i).getTel(), i, 3);
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new cliente().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_edit_cli;
    private javax.swing.JButton btn_exclude_cli;
    private javax.swing.JRadioButton btn_fem;
    private javax.swing.JRadioButton btn_masc;
    private javax.swing.JButton btn_novo_cli;
    private javax.swing.JButton btn_salvar_cli;
    private javax.swing.JComboBox com_estcivil_cli;
    private javax.swing.JLabel fundo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tabela_cli;
    private javax.swing.JTextField tf_bairro_cli;
    private javax.swing.JFormattedTextField tf_cep_cli;
    private javax.swing.JTextField tf_cidade_cli;
    private javax.swing.JTextField tf_compl_cli;
    private javax.swing.JFormattedTextField tf_cpf_cli;
    private javax.swing.JFormattedTextField tf_data_nasc_cli;
    private javax.swing.JTextField tf_email_cli;
    private javax.swing.JTextField tf_end_cli;
    private javax.swing.JTextField tf_nome_cli;
    private javax.swing.JTextField tf_num_cli;
    private javax.swing.JFormattedTextField tf_tel_cli;
    // End of variables declaration//GEN-END:variables
}
